#include "DialServicesSDK.h"
#include <unistd.h>
#include <cstring>
using namespace std;

void userServicsFunc(char * pReqBuf, int reqLen, char ** pRespBuf, int *respLen);
void userServicsResp(char * pRespBuf);



int main(int argc, char *argv[] )
{
    string servName;
	CDialServicerAPI dialServicerAPI;
    int iRet;
	
    if (argc < 2)
    {
        printf ("print enter server name , exit .\n");
		return -1;
    }

	servName = argv[1];
	
    iRet = dialServicerAPI.ServiceStart(servName, userServicsFunc, userServicsResp);
	if (iRet != 0)
	{
		printf ("ServiceStart failed , servName=%s, errno=%d !\n", servName.c_str(), iRet);
		return -1;
	}
	else
	{
		printf ("ServiceStart success!\n");
	}
	
	while (1)
	{
	    sleep(10);
		//printf("do mosquitto_reconnect_async\n");
		//mosquitto_reconnect_async(dialServicerAPI.GetServMosq());
	}
    return 1;
}



void userServicsFunc(char * pReqBuf, int reqLen, char ** pRespBuf, int *respLen)
{
    
    //if (strncmp(pReqBuf, "ping", strlen("ping")))
    {
        *respLen = strlen("pong");
    	*pRespBuf = (char*)malloc(*respLen);
		strncpy(*pRespBuf,"pong",*respLen);
    }
	
}

void userServicsResp(char * pRespBuf)
{
    if (pRespBuf != NULL)
    {
        free(pRespBuf);
    }
}
